package order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@RequestMapping("/order")
@ResponseBody
@RefreshScope
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;
//    @Autowired
//    private GoodsClient goodsClient;
@Value("${remote}")
private String remote;
    @GetMapping ("/testPost")
    public String testPost(){
        System.out.println("postman 调用成功!");
        return "postman 调用成功!";
    }

    /**
     * 调用订单接口,并查询商品信息
     * */
    @PostMapping("/goodsByOrder")
    public String goodsByOrder(){
        System.out.println("调用订单接口,并查询商品信息");
        String result = restTemplate.postForObject("http://goodsService/goods/getGoods", "", String.class);
        //  String result = restTemplate.postForObject("http://127.0.0.1:8081/goods/getGoods","",String.class);
        System.out.println("result:" + remote);
        return remote;
    }

    /**
     * 测试 nacos 配置中心
     */
    @GetMapping("/testNacosConfiguration")
    public String testNacosConfiguration() {
        System.out.println("testNacosConfiguration");
        return remote;
    }
}
